import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   如果设置为true，则项目将不会显示在侧边栏中（默认为false）
 * alwaysShow: true               如果设置为true，将始终显示根菜单
 *                                如果不始终设置Show，则当项具有多个子路由时，
 *                                它将成为嵌套模式，否则不显示根菜单
 * redirect: noRedirect           如果设置为no redirect，则breadcrumb中不会重定向
 * name:'router-name'             该名称由<keep alive>使用（必须设置！!!)
 * meta : {
    roles: ['admin','editor']    控制页面角色（可以设置多个角色）
    title: 'title'               侧边栏和面包屑中显示的名称（推荐设置）
    icon: 'svg-name'             显示在侧栏中的图标
    breadcrumb: false            如果设置为false，则该项将隐藏在breadcrumb中（默认为true）
    activeMenu: '/example/list'  如果设置路径，侧边栏将突出显示您设置的路径
  }
 */

/**
 * 用户类别
 * admin: 开发
 * 127: 多媒体_普通用户
 * 128: 多媒体_素材审核管理员
 * 129: 多媒体_终端发布管理员
 * -1（terminal）: 终端登录
 */


/**
 * constantRoutes
 * 没有权限要求的基页
 * 所有角色可以访问
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/redirect',
    children: [
      {
        path: 'redirect',
        component: () => import('@/views/redirect/index'),
        name: 'Redirect',
        hidden: true,
      }
    ]
  },

  {
    path: '/personal',
    component: Layout,
    redirect: '/personal/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/personal/index'),
        name: 'Personal',
        meta: { title: '个人中心', icon: '' },
        hidden: true
      }
    ]
  },
  // {
  //   path: '/system',
  //   component: Layout,
  //   name: 'System',
  //   redirect: '/System/User',
  //   meta: { title: '系统管理', icon: '' },
  //   children: [
  //     {
  //       path: 'user',
  //       component: () => import('@/views/system/user/index'),
  //       name: 'User',
  //       meta: { title: '用户管理', icon: 'user' },
  //       hidden: true
  //     }
  //   ]
  // },
]


/**
 * 异步路由
 * 需要根据用户角色动态加载的路由
 */
export const asyncRoutes = [

  {
    path: '/system',
    component: Layout,
    redirect: '/System/User',
    name: 'System',
    meta: { title: '系统管理', icon: 'system'},
    children: [
      {
        path: 'user',
        name: 'User',
        component: () => import('@/views/system/user/index'),
        meta: { title: '用户管理', icon: 'user'}
      },
	  {
	    path: 'role_role',
	    name: 'role_role',
	    component: () => import('@/views/system/role_role/index'),
	    meta: { title: '角色管理', icon: 'role_role'}
	  },
	  {
	    path: 'menu_menu',
	    name: 'menu_menu',
	    component: () => import('@/views/system/menu_menu/index'),
	    meta: { title: '菜单管理', icon: 'menu_menu'}
	  },
	  {
	    path: 'organization',
	    name: 'organization',
	    component: () => import('@/views/system/organization/index'),
	    meta: { title: '组织机构', icon: 'organization'}
	  }
	
    ]
  },
  {
     path: '/news',
     component: Layout,
     redirect: '/News/Column',
     name: 'News',
     meta: { title: '资讯管理', icon: 'advisory'},
     children: [
       {
         path: 'column',
         name: 'Column',
         component: () => import('@/views/news/column/columnIndex'),
         meta: { title: '资讯栏目', icon: ''}
       },
       {
         path: 'news_det',
         name: 'News_det',
         component: () => import('@/views/news/news_det/managementIndex'),
         meta: { title: '资讯管理', icon: ''}
       },
     ]
   },
   {
     path: '/sys_notice',
     component: Layout,
     redirect: '/Sys_notice/Notic_manage',
     name: 'Sys_notice',
     meta: { title: '公告管理'},
     children: [
       {
         path: 'notic_manage',
         name: 'Notic_manage',
         component: () => import('@/views/sys_notice/notic_manage/noticeIndex'),
         meta: { title: '公告管理', icon: ''}
       }]
   },
  {
    path: '/application',
    component: Layout,
    redirect: '/application/category',
    name: 'News',
    meta: { title: '应用管理', icon: 'advisory'},
    children: [
		{
		  path: 'type',
		  name: 'type',
		  component: () => import('@/views/application_application/type/index'),
		  meta: { title: '应用类型', icon: ''}
		},
      {
        path: 'category',
        name: 'category',
        component: () => import('@/views/application_application/category/index'),
        meta: { title: '应用类别', icon: ''}
      },
      {
        path: 'application_management',
        name: 'application_management',
        component: () => import('@/views/application_application/application_management/index'),
        meta: { title: '应用管理', icon: ''}
      },
    ]
  },
  {
    path: '/Dashboard',
    component: Layout,
    redirect: '/Dashboard/dataAcquisition',
    name: 'Dashboard',
    meta: { title: '数据采集', icon: 'el-icon-s-order', roles: ['admin', '127', '128'] },
    children: [
      {
        path: 'dataAcquisition',
        name: 'DataAcquisition',
        component: () => import('@/views/dashboard/dataAcquisition/index'),
        meta: { title: '数据录入', icon: '', roles: ['admin', '127'] },
        hidden: false
      },
      {
        path: 'dataAudit',
        name: 'DataAudit',
        component: () => import('@/views/dashboard/dataAudit/index'),
        meta: { title: '数据审核', icon: '', roles: ['admin', '128'] },
        hidden: false
      },
      {
        path: 'dashboardEdit',
        name: 'DashboardEdit',
        component: () => import('@/views/dashboard/dataAcquisition/editData'),
        meta: { title: '编辑图文', icon: '' },
        hidden: true
      },
      {
        path: 'dashboardDetails',
        name: 'DashboardDetails',
        component: () => import('@/views/dashboard/dataAcquisition/details'),
        meta: { title: '图文详情', icon: '' },
        hidden: true
      },
      {
        path: 'dashboardAddData',
        name: 'DashboardAddData',
        component: () => import('@/views/dashboard/dataAcquisition/addData'),
        meta: { title: '新建图文', icon: '' },
        hidden: true
      }
    ]
  },
  {
    path: '/ControlModule',
    component: Layout,
    redirect: '/ControlModule/material',
    name: 'ControlModule',
    meta: { title: '中控模块', icon: 'el-icon-s-help', roles: ['admin', '128', '129'] },
    children: [
      {
        path: 'material',
        name: 'Material',
        component: () => import('@/views/controlModule/materialRelease'),
        meta: { title: '素材发布中心', icon: '', roles: ['admin', '129'] },
        hidden: false
      },
      { 
        path: 'http://sj.szcasic.com:5910/bpm/login?type=0',
        name: '流程定制中心',
        meta: { title: '流程定制中心', icon: '', roles: ['admin', '128', '129'] },
        hidden: false
      },
      { 
        path: 'http://jc.szcasic.com:8080/fwp/login?type=0',
        name: '自由网页定制',
        meta: { title: '自由网页定制', icon: '', roles: ['admin', '128', '129']  },
        hidden: false
      },
      {
        path: 'materialDetails',
        name: 'MaterialDetails',
        component: () => import('@/views/controlModule/details'),
        meta: { title: '图文详情', icon: '' },
        hidden: true
      }
    ]
  },
  {
    path: '/TerminalManagement',
    component: Layout,
    redirect: '/TerminalManagement/software',
    name: 'TerminalManagement',
    meta: { title: '终端管理', icon: 'el-icon-s-tools', roles: ['admin', '129'] },
    children: [
      {
        path: 'software',
        name: 'Software',
        component: () => import('@/views/terminalManagement/software'),
        meta: { title: '软件终端', icon: '', roles: ['admin', '129'] },
        hidden: false
      },
      {
        path: 'hardware',
        name: 'Hardware',
        component: () => import('@/views/terminalManagement/hardware'),
        meta: { title: '硬件终端', icon: '', roles: ['admin', '129'] },
        hidden: false
      }
    ]
  },
  {
    path: '/TerminalPreview',
    component: Layout,
    redirect: '/TerminalPreview/terminal',
    name: 'TerminalPreview',
    meta: { title: '终端预览', icon: 'el-icon-s-platform', roles: ['admin', '129', 'terminal'] },
    children: [
      {
        path: 'terminal',
        name: 'Terminal',
        redirect: '/TerminalPreview/terminal/terminalList',
        component: () => import('@/views/terminalPreview/index'),
        meta: { title: '终端列表', icon: '', roles: ['admin', '129', 'terminal'] },
        hidden: false,
        children: [
          {
            path: 'terminalList',
            name: 'TerminalList',
            component: () => import('@/views/terminalPreview/terminal'),
            meta: { title: '', icon: '', roles: ['admin', '129', 'terminal'] },
            hidden: true
          },
          {
            path: 'wxList',
            name: 'WELIST',
            component: () => import('@/views/terminalPreview/terminalList/wxList'),
            meta: { title: '微信公众号预览', icon: '', roles: ['admin', '129', 'wxList'] },
            hidden: true
          },
          {
            path: 'ydList',
            name: 'YDIDLIST',
            component: () => import('@/views/terminalPreview/terminalList/ydptList'),
            meta: { title: '移动平台服务号预览', icon: '', roles: ['admin', '129', 'ydList'] },
            hidden: true
          },
          {
            path: 'otherList',
            name: 'OTHERLIST',
            component: () => import('@/views/terminalPreview/terminalList/tymhList'),
            meta: { title: '统一门户预览', icon: '', roles: ['admin', '129', 'otherList'] },
            hidden: true
          },
          {
            path: 'hardwareList',
            name: 'HARDWAREList',
            component: () => import('@/views/terminalPreview/terminalList/xszdList'),
            meta: { title: '显示终端预览', icon: '', roles: ['admin', '129', 'hardware'] },
            hidden: true
          },
          {
            path: 'terminalDetails',
            name: 'TerminalDetails',
            component: () => import('@/views/terminalPreview/details'),
            meta: { title: '图文详情', icon: '' },
            hidden: true
          }
        ]
      }
    ]
  },

  // 404 页面必须放在末尾 !!!
  { path: '*', redirect: '/404', hidden: true }
]
const createRouter = () => new Router({
  // mode: 'history', // 需要服务支持
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()


export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // 重置路由器
}

export default router
